package com.ruoyi.web.wx.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.web.wx.entity.TrashSetting;
import com.ruoyi.web.wx.entity.TrashVO;
import com.ruoyi.web.wx.mapper.TrashSettingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.wx.mapper.TrashMapper;
import com.ruoyi.web.wx.entity.Trash;
import com.ruoyi.web.wx.service.ITrashService;
import com.ruoyi.common.core.text.Convert;

/**
 * 回收垃圾 服务层实现
 * 
 * @author ruoyi
 * @date 2019-08-27
 */
@Service("trashService")
public class TrashServiceImpl implements ITrashService 
{
	@Autowired
	private TrashMapper trashMapper;
	@Autowired
	private TrashSettingMapper trashSettingMapper;
	/**
     * 查询回收垃圾信息
     * 
     * @param id 回收垃圾ID
     * @return 回收垃圾信息
     */
    @Override
	public Trash selectTrashById(String id)
	{
	    return trashMapper.selectTrashById(id);
	}
	
	/**
     * 查询回收垃圾列表
     * 
     * @param trash 回收垃圾信息
     * @return 回收垃圾集合
     */
	@Override
	public List<Trash> selectTrashList(Trash trash)
	{
	    return trashMapper.selectTrashList(trash);
	}
	
    /**
     * 新增回收垃圾
     * 
     * @param trash 回收垃圾信息
     * @return 结果
     */
	@Override
	public int insertTrash(Trash trash)
	{
	    return trashMapper.insertTrash(trash);
	}
	
	/**
     * 修改回收垃圾
     * 
     * @param trash 回收垃圾信息
     * @return 结果
     */
	@Override
	public int updateTrash(Trash trash)
	{
	    return trashMapper.updateTrash(trash);
	}

	/**
     * 删除回收垃圾对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteTrashByIds(String ids)
	{
		return trashMapper.deleteTrashByIds(Convert.toStrArray(ids));
	}

	@Override
	public List<TrashVO> getListByType(String type) {
		List<TrashVO> list= new ArrayList<>();
		if ("1001".equals(type)){
			list=trashMapper.getListByType("3");
		}if ("1002".equals(type)){
			list=trashMapper.getListByType("2");
		}if ("1003".equals(type)){
			list=trashMapper.getListByType("1");
		}if ("1004".equals(type)){
			list=trashMapper.getListByType("4");
		}
		if (list!=null&&list.size()>0){
			for (TrashVO trashVO : list) {
				String id = trashVO.getId();
				TrashSetting trashSetting = new TrashSetting();
				trashSetting.setTrashId(id);
				List<TrashSetting> trashSettings = trashSettingMapper.selectTrashSettingList(trashSetting);
				trashVO.setList(trashSettings);
			}

		}
		return list;
	}

}
